// 认证相关API
const API_BASE = 'http://localhost:8080/api';

export async function checkEmail(email) {
  const response = await fetch(`${API_BASE}/auth/check-email`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email })
  });
  return await response.json();
}

export async function sendCode(email) {
  const response = await fetch(`${API_BASE}/auth/send-code`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email })
  });
  return await response.json();
}

export async function loginWithPassword(email, password) {
  const response = await fetch(`${API_BASE}/auth/login`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email, password })
  });
  return await response.json();
}

export async function loginWithCode(email, code) {
  const response = await fetch(`${API_BASE}/auth/login-with-code`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email, code })
  });
  return await response.json();
}

export async function register({ name, email, password, code }) {
  const response = await fetch(`${API_BASE}/auth/register`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ name, email, password, code })
  });
  return await response.json();
} 

export async function updatePassword(oldPassword, newPassword) {
  const response = await fetch(`${API_BASE}/auth/update-password`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ oldPassword, newPassword })
  });
  return await response.json();
}
